package com.stqf.scala.jdk8;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by ASUS on 2018-02-01.
 */
public class FlatMapResearch {

    private static final Logger log = LoggerFactory.getLogger(FlatMapResearch.class);

    public static void main(String[] args) {

        List<String> items = new ArrayList<>();
        items.add("hello world");
        items.add("good good study");
        items.add("day day up");
        items.add("lang lang");
        items.add("there parent");
        List<?> proItems = items.stream().map(temp -> temp.split(" ")).collect(Collectors.toList());
        proItems.forEach(i -> log.info("items ... {}", i));

        List<String> words = items.stream().flatMap(k -> {
            String[] split = k.split(" ");
            return Arrays.stream(split);
        }).collect(Collectors.toList());
        log.debug("words ... {}", words);
    }
}
